package com.sohoometer;

import java.util.HashSet;
import java.util.Set;

import org.quartz.CronScheduleBuilder;
import org.quartz.CronTrigger;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.ListenerManager;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.JobDetailImpl;
import org.quartz.impl.StdSchedulerFactory;


public class JobDemo {
	
	public static void main(String[] args) throws Exception {
		JobBuilder jobBuilder = JobBuilder.newJob(JobImpl.class);
		JobDetail job = jobBuilder.withIdentity("test").build();
//		TriggerBuilder<Trigger> newTrigger = TriggerBuilder.newTrigger();
//		newTrigger.withIdentity("Hello").forJob(s).build();
		
//	 JobBuilder newJob = JobBuilder.newJob();
	 CronScheduleBuilder scheduleBuilder =  CronScheduleBuilder.cronSchedule("0 0/10 * * * ? ");//每隔10分钟跑一次
	 TriggerBuilder<CronTrigger> triggerBuilder = TriggerBuilder.newTrigger().forJob(job).withIdentity("test3").startNow().withSchedule(scheduleBuilder);
	 CronTrigger trigger = triggerBuilder.build();
	 SchedulerFactory factory = new StdSchedulerFactory();
	 Set<Trigger> triggers = new HashSet<>();
	 triggers.add(trigger);
	 Scheduler scheduler = factory.getScheduler();
	 ListenerManager listenerManager = scheduler.getListenerManager();
	 scheduler.scheduleJob(job, triggers, true);
	 scheduler.start();
//	 Thread.currentThread().sleep(10000000);
	}
}

